package com.gaohe.official.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.official.domain.FmCommunity;
import com.gaohe.official.service.IFmCommunityService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 论坛圈子Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/community")
public class FmCommunityController extends BaseController
{
    @Autowired
    private IFmCommunityService fmCommunityService;

    /**
     * 查询论坛圈子列表
     */
    @RequiresPermissions("official:community:list")
    @GetMapping("/list")
    public TableDataInfo list(FmCommunity fmCommunity)
    {
        startPage();
        List<FmCommunity> list = fmCommunityService.selectFmCommunityList(fmCommunity);
        return getDataTable(list);
    }

    /**
     * 导出论坛圈子列表
     */
    @RequiresPermissions("official:community:export")
    @Log(title = "论坛圈子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmCommunity fmCommunity)
    {
        List<FmCommunity> list = fmCommunityService.selectFmCommunityList(fmCommunity);
        ExcelUtil<FmCommunity> util = new ExcelUtil<FmCommunity>(FmCommunity.class);
        util.exportExcel(response, list, "论坛圈子数据");
    }

    /**
     * 获取论坛圈子详细信息
     */
    @RequiresPermissions("official:community:query")
    @GetMapping(value = "/{communityId}")
    public AjaxResult getInfo(@PathVariable("communityId") Long communityId)
    {
        return success(fmCommunityService.selectFmCommunityByCommunityId(communityId));
    }

    /**
     * 新增论坛圈子
     */
    @RequiresPermissions("official:community:add")
    @Log(title = "论坛圈子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmCommunity fmCommunity)
    {
        return toAjax(fmCommunityService.insertFmCommunity(fmCommunity));
    }

    /**
     * 修改论坛圈子
     */
    @RequiresPermissions("official:community:edit")
    @Log(title = "论坛圈子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmCommunity fmCommunity)
    {
        return toAjax(fmCommunityService.updateFmCommunity(fmCommunity));
    }

    /**
     * 删除论坛圈子
     */
    @RequiresPermissions("official:community:remove")
    @Log(title = "论坛圈子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{communityIds}")
    public AjaxResult remove(@PathVariable Long[] communityIds)
    {
        return toAjax(fmCommunityService.deleteFmCommunityByCommunityIds(communityIds));
    }
}
